package com.bgybmi.entity;

import java.util.List;

import com.jfinal.plugin.activerecord.ActiveRecordException;
import com.jfinal.plugin.activerecord.Model;

public class JbRoom extends Model<JbRoom>{

	public static final JbRoom me = new JbRoom();
	/**
	 * @description show all base room
	 * @return
	 */
	private static final String tablename="jb_room"; 
	
	public List<JbRoom> getAllBase(){
		return me.find("select * from jb_room where flag=0");
	}
	 
	public List<JbRoom> getAllCreate(String userid,String groupid){
		return me.find("select jb.* from jb_room jb where flag=1 and groupid=?",groupid);
		//return me.find("select jb.* from jb_room jb, where flag=1 and userid=? and groupid=?",userid,groupid);
	}
    
	//save
	public boolean save(String roomname,String bz,String userid, String groupid){				
		JbRoom  me = new  JbRoom ();
		me.set("roomname",roomname);
        me.set("bz", bz);
        me.set("flag", 1);
        me.set("userid",userid);
        me.set("groupid", groupid);
		boolean result = false;
		try{
			result = me.save();			
		}catch(ActiveRecordException E){
			E.printStackTrace();
		}
		return result;
	}

	public List<JbRoom> getAllList(String userid) {
		// TODO Auto-generated method stub
		return me.find("select * from jb_room where flag=0 or (flag=1 and userid=?)",userid);
	}
	
	public List<JbRoom> listRoom(String room){
		return me.find(CommonStatic.listByParam(tablename,"roomname"),room);
	}

}
